package com.whut.transportation;

import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.TextView;

import com.whut.transportation.entity.TaskInfo;
import com.whut.transportation.entity.TransInfo;
import com.whut.transportation.network.HttpManager;
import com.whut.transportation.network.HttpRequestVo;
import com.whut.transportation.parser.JSONParser;
import com.whut.transportation.ui.BaseActivity;
import com.whut.transportation.utils.Constant;
/**
 * 查询已经完成的卸车信息
 * @author yuliyan
 *
 */
public class UnloaCompletedDetailActivity extends BaseActivity {
	
	private TextView unload_number;
	private TextView unload_trainNum;
	private TextView unload_train;
	private TextView unload_station;
	private TextView unload_goods;
	private TextView unload_name;
	private TextView unload_weight;
	private TextView unload_gudao;
	private TextView unload_time;
	private TextView unload_begin_time;
	private TextView unload_end_time;
	private TextView unload_buNum;
	
	private TransInfo transinfo;
	private TaskInfo taskInfo;
	
	private SharedPreferences preferences;
	
	
	@Override
	protected void loadViewLayout() {
		setContentView(R.layout.activity_unload_complete_detail);
		Intent intent = getIntent();
		transinfo = (TransInfo)intent.getSerializableExtra("transinfo");
		preferences=getSharedPreferences("userId", Context.MODE_PRIVATE);
		//类型为1时为装车  0为卸车
		String tag = "卸车";
		if(transinfo.getType()==1)
			tag = "装车";
		setTitleBarView(true, transinfo.getTrainNumber()+transinfo.getTrain()+tag+"信息", -1, true);
	}
	@Override
	protected void findViewById() {
		unload_number = (TextView) findViewById(R.id.unload_number);
		unload_trainNum = (TextView) findViewById(R.id.unload_trainNum);
		unload_train = (TextView) findViewById(R.id.unload_train);
		unload_station = (TextView) findViewById(R.id.unload_station);
		unload_goods = (TextView) findViewById(R.id.unload_goods);
		unload_name = (TextView) findViewById(R.id.unload_name);
		unload_weight = (TextView) findViewById(R.id.unload_weight);
		unload_gudao = (TextView) findViewById(R.id.unload_gudao);
		unload_time = (TextView) findViewById(R.id.unload_time);
		unload_begin_time = (TextView) findViewById(R.id.unload_begin_time);
		unload_end_time = (TextView) findViewById(R.id.unload_end_time);
		unload_buNum = (TextView) findViewById(R.id.unload_buNum);
	}

	@Override
	protected void afterFindViewId() {
		unload_number.setText(unload_number.getText()+transinfo.getNumber());
		unload_trainNum.setText(unload_trainNum.getText()+transinfo.getTrainNumber());
		unload_train.setText(unload_train.getText()+transinfo.getTrain());
		unload_station.setText(unload_station.getText()+transinfo.getStation());
		unload_goods.setText(unload_goods.getText()+transinfo.getGoods());
		unload_name.setText(unload_name.getText()+transinfo.getName());
		unload_weight.setText(unload_weight.getText()+String.valueOf(transinfo.getWeight()+"t"));
		unload_gudao.setText(unload_gudao.getText()+String.valueOf(transinfo.getGudao()));
	}

	@Override
	protected void processLogic() {
		//查询已经完成的卸车记录的信息
		HttpRequestVo vo = new HttpRequestVo();
		vo.requestUrl = Constant.Find_TASK_INFO;
		vo.context = mContext;
		
		HashMap<String, String> req = new HashMap<String, String>();
		req.put("taskInfo.trainSerialId", transinfo.getNumber());
		vo.requestDataMap = req;
		vo.parser = new JSONParser(TaskInfo.class);
		getDataFromServer(HttpManager.POST_MOTHOD, vo, 
				new DataCallback<HashMap<String, Object>>() {
					@Override 
					public void onStart() {
					}
					@Override
					public void onFailed() {
						showNetErrorDialog();
					}
					@Override
					public void processData(
							HashMap<String, Object> paramObject,
							boolean paramBoolean) {
						//将查询出来的卸车信息放入到界面中
						taskInfo = (TaskInfo) paramObject.get("result");
						unload_time.setText(unload_time.getText()+taskInfo.getIntime().trim());
						unload_begin_time.setText(unload_begin_time.getText()+taskInfo.getBegintime().trim());
						unload_end_time.setText(unload_end_time.getText()+taskInfo.getEndtime().trim());
						unload_buNum.setText(unload_buNum.getText()+taskInfo.getBunum().trim());
						}
					@Override
					public void onFinish() {
						// TODO Auto-generated method stub
						closeProgressDialog();
					}

				});
		
	}

	@Override
	protected void setListener() {
	}

	@Override
	protected void getDataAgain() {
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.unload_submit:
			break;
		default:
			break;
		}
		super.onClick(v);
		
		
		
	}
	
}
